package tutorial.gae;

import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.google.appengine.api.datastore.EntityNotFoundException;


@Path("/datastore/contact")
public class ContactService {
	
	//private ContactDao dao = new ContactDao();
	private ContactJpaDao dao = new ContactJpaDao();
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public Contact get( @QueryParam("id") long id) 	{
	//	try {
			return dao.get(id);
		//} catch (EntityNotFoundException e) {
			// TODO Auto-generated catch block
	//		return null;
		//}
		
	}
	
	@POST
	@Produces(MediaType.APPLICATION_JSON)
	public Contact create(
			@FormParam("firstName") String firstName,
			@FormParam("lastName") String lastName,
			@FormParam("address") String address,
			@FormParam("memo") String memo,
			@FormParam("phone") String phone) {
		Contact c = new Contact();
		c.setAddress(address);
		c.setFirstName(firstName);
		c.setLastName(lastName);
		c.setMemo(memo);
		c.setPhone(phone);
		return dao.create(c);
		
		
	}
	

}
